package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.service.IReservationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.jaxb.SpringDataJaxb;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 * @date 2025-03-02
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "预约信息的接口")
@Slf4j
public class ReservationController extends BaseController
{
    @Autowired
    private IReservationService reservationService;

    /**
     * 查询预约信息列表
     */
    @ApiOperation("查询预约信息列表")
    @GetMapping("/list")
    public TableDataInfo list(Reservation reservation)
    {
        startPage();
        List<Reservation> list = reservationService.selectReservationList(reservation);
        return getDataTable(list);
    }

    /**
     * 导出预约信息列表
     */
    @ApiOperation("导出预约信息列表")
    @Log(title = "预约信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Reservation reservation)
    {
        List<Reservation> list = reservationService.selectReservationList(reservation);
        ExcelUtil<Reservation> util = new ExcelUtil<Reservation>(Reservation.class);
        util.exportExcel(response, list, "预约信息数据");
    }

//    /**
//     * 获取预约信息详细信息
//     */
//    @ApiOperation("获取预约信息详细信息")
//    @PreAuthorize("@ss.hasPermi('member:reservation:query')")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@ApiParam(value = "预约信息ID", required = true)
//            @PathVariable("id") Long id)
//    {
//        return success(reservationService.selectReservationById(id));
//    }

    /**
     * 新增预约信息
     */
    @ApiOperation("新增预约信息")
    @Log(title = "预约信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam(value = "预约信息实体")
            @RequestBody ReservationDto reservationDto)
    {
        return toAjax(reservationService.insertReservation(reservationDto));
    }

    @ApiOperation("查询当天取消预约数量")
    @GetMapping("/cancelled-count")
    public AjaxResult reservationListRm()
    {
        return success(reservationService.reservationListRm());

    }

    @ApiOperation("查询每个时间段剩余预约次数")
    @GetMapping("/countByTime")
    public AjaxResult reservationList( Long time)
    {
        return AjaxResult.success("操作成功",reservationService.reservationList(time));

    }

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public AjaxResult reservationPage(Integer pageSize, Integer pageNum, Integer status)
    {

        return AjaxResult.success(getDataTableMP(reservationService.reservationPage(pageSize,pageNum,status)));

    }


    /**
     * 查询预约信息列表
     */

    /**
     *取消预约
     */
    @ApiOperation("取消预约")
    @PutMapping("/{id}/cancel")
    public AjaxResult cancel(@PathVariable("id") Long id) {
        log.info("取消预约");
        return toAjax(reservationService.cancel(id));
    }

}
